<?php

namespace common\models;

use Yii;

/**
 * This is the model class for table "{{%classify}}".
 *
 * @property int $id
 * @property string|null $name 名称
 * @property int|null $status 状态
 * @property int|null $sort 排序
 * @property string|null $create_time 创建时间
 * @property string|null $create_user 创建人
 * @property string|null $update_time 修改时间
 * @property string|null $update_user 修改人
 * @property int|null $delete 删除
 */
class Classify extends BaseModel
{
    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return '{{%classify}}';
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['status', 'sort', 'delete'], 'integer'],
            [['create_time', 'update_time'], 'safe'],
            [['name', 'create_user', 'update_user'], 'string', 'max' => 255],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'name' => '名称',
            'status' => '状态',
            'sort' => '排序',
            'create_time' => '创建时间',
            'create_user' => '创建人',
            'update_time' => '修改时间',
            'update_user' => '修改人',
            'delete' => '删除',
        ];
    }

    /**
     * 获取所有分类
     * @param int[] $where 条件
     * @param callable|null $callable 回调
     * @return array|\yii\db\ActiveRecord[]
     */
    public static function getAll($where=['delete'=>0],callable $callable=null)
    {
        $data = self::find()->where($where)->asArray()->all();
        if ($callable){
            $data = $callable($data);
        }
        return $data;
    }
}
